package com.example.warehouse.sys.controller;

import com.example.warehouse.common.web.JsonResult;
import com.example.warehouse.sys.pojo.param.AddNewRolePermissionParam;
import com.example.warehouse.sys.pojo.vo.RolePermissionVO;
import com.example.warehouse.sys.service.IRolePermissionService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/sys/rolepermission")
@Slf4j
@Validated
@Api(tags = "6.2. 角色分配权限管理")
public class RolePermissionController {
    @Autowired
    private IRolePermissionService rolePermissionService;

    @ApiOperation("角色分配权限")
    @ApiOperationSupport(order = 120)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "permissionIdList", value = "权限集合", defaultValue = "1"),
            @ApiImplicitParam(name = "id", value = "角色id", defaultValue = "2", dataType = "long")
    })
    @PostMapping("/{id}/addNew")
    public JsonResult addNewRolePermissionByList(@RequestBody @Validated List<Long> permissionIdList, @PathVariable Long id){
        System.out.println("permissionIdList:"+permissionIdList );
        rolePermissionService.addNewRolePermissionByList(id,permissionIdList);
        return JsonResult.ok();
    }

    @ApiOperation("角色权限id")
    @ApiOperationSupport(order = 420)
    @ApiImplicitParams({

            @ApiImplicitParam(name = "id", value = "角色id", defaultValue = "1", dataType = "long")
    })
    @GetMapping("/{id:[0-9]+}/list")
    public JsonResult getRoleForPermission(@PathVariable Long id){
        List<Long> rolePermission = rolePermissionService.selectByRoleId(id);
        return JsonResult.ok(rolePermission);
    }
}
